-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(angular.copy) support for Map and Set #15697
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
1 similar comment
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
signed! |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
1 similar comment
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
updated email for CLA |
CLAs look good, thanks! |
1 similar comment
CLAs look good, thanks! |
@mrohr After you asked on gitter, I did some digging in the reason why the tests was failing in IE11, it looks like
I created a fiddle to demonstrate the issue outside angularjs: https://jsfiddle.net/0mstLj6q/7/ Running this plunkr in IE11 (Windows 10) shows: Running this in Chrome shows: |
case '[object Map]': | ||
// If we're in this case we know the environment supports Map | ||
/* eslint-disable no-undef */ | ||
var copiedMap = new Map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We access globals through the window
in order to support non-browser environments (such as jsdom).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had originally used new source.constructor() here, tried changing it to Map/Set to deal /w the IE11 issue that is failing the build. My next update I will change it back
/* eslint-disable no-undef */ | ||
var copiedMap = new Map(); | ||
/* eslint-enable */ | ||
source.forEach(function(value, key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't return new Map(source)
work as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this correctly, IE11 does not support Map and Set constructor with arguments ? https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/Map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to copy the keys/values, not just assign them, probably by invoking copyRecurse
so we also get the maxDepth
behavior.
@frederikprijck Thanks for your help, I'm guessing this feature is pretty much stuck, unless we set up the tests to not run in browsers that don't print map/set objects .toString() as '[object Map]'/'[object Set]'? |
Or are there alternative approaches available to detect Map and Set in IE11 (or all browsers)? I just did some debugging and this validates to true in Chrome and IE11:
aswell as
|
There are a couple of problems with this feature (which are not specific to the feature itself, rather general problems with similar features):
For these reasons, I am going to put it in the Ice Box for now (but I am open to being convinced otherwise - now or in the future 😃). |
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
bug fix
What is the current behavior? (You can also link to an open issue here)
the copied Map or Set will fail to call functions with an error such as:
TypeError: Method Map.prototype.size called on incompatible receiver #
What is the new behavior (if this is a feature change)?
angular.copy will now property create new Map or Set objects with the same values as the source.
Does this PR introduce a breaking change?
No
Please check if the PR fulfills these requirements
Other information: